<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>首页</title>
</head>
<body>
<h1>微博首页</h1>
<div>
    <div v-if="isLogin">
        <p>欢迎{{user.nick}}回来!</p>
        <a href="insert.html">发布微博</a>
        <a href="javascript: void(0)" @click="logout()">退出</a>
    </div>
    <div v-else>
        <a href="/reg.html">注册</a>
        <a href="/login.html">登录</a>
    </div>
    <!--显示所有微博数据-->
    <hr>
    <div v-for="weibo in arr">
        <h2>{{weibo.nick}}:</h2>
        <h4>{{weibo.content}}</h4>
        <img :src="weibo.url" style="width: 300px" alt="图片">
        <i style="font-size: 5px">发表时间:{{weibo.created}}</i>
    </div>
</div>
<script src="js/vue.js"></script>
<script src="js/axios.min.js"></script>

<script>
    let v = new Vue({
        el:"body>div",
        data:{
            isLogin:false,
            user:{},
            arr:[]
        },
        created: function (){
            axios.get("/currentUser").then(function (response){
                v.user = response.data;
                //如果当前客户端没有登录的话得到的是空字符串
                v.isLogin = v.user==""?false:true;
            })
            //发请求获取所有微博信息
            axios.get("/select").then(function (response){
                v.arr = response.data;
            })
        },
        methods:{
            logout(){
                //发出退出登录请求
                axios.get("/logout").then(function (response){
                    location.reload();
                })
            }
        }
    })
</script>
</body>
</html>